<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="uid">
      <el-input v-model="dataForm.uid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="订单号" prop="orderNo">
      <el-input v-model="dataForm.orderNo" placeholder="订单号"></el-input>
    </el-form-item>
    <el-form-item label="退税凭证" prop="imageUrl">
      <el-input v-model="dataForm.imageUrl" placeholder="退税凭证"></el-input>
    </el-form-item>
    <el-form-item label="退税方式:1(银行卡);2(支付宝);3(微信)..." prop="transferType">
      <el-input v-model="dataForm.transferType" placeholder="退税方式:1(银行卡);2(支付宝);3(微信)..."></el-input>
    </el-form-item>
    <el-form-item label="退税金额" prop="taxPrice">
      <el-input v-model="dataForm.taxPrice" placeholder="退税金额"></el-input>
    </el-form-item>
    <el-form-item label="税点" prop="taxPoint">
      <el-input v-model="dataForm.taxPoint" placeholder="税点"></el-input>
    </el-form-item>
    <el-form-item label="银行卡号或支付宝、微信账号" prop="accountNo">
      <el-input v-model="dataForm.accountNo" placeholder="银行卡号或支付宝、微信账号"></el-input>
    </el-form-item>
    <el-form-item label="开户行" prop="bankName">
      <el-input v-model="dataForm.bankName" placeholder="开户行"></el-input>
    </el-form-item>
    <el-form-item label="持卡人姓名" prop="realName">
      <el-input v-model="dataForm.realName" placeholder="持卡人姓名"></el-input>
    </el-form-item>
    <el-form-item label="电话" prop="phone">
      <el-input v-model="dataForm.phone" placeholder="电话"></el-input>
    </el-form-item>
    <el-form-item label="申请退税状态:0(已提交,未审核);1(已审核);2(已到账，审核结束)" prop="status">
      <el-input v-model="dataForm.status" placeholder="申请退税状态:0(已提交,未审核);1(已审核);2(已到账，审核结束)"></el-input>
    </el-form-item>
    <el-form-item label="" prop="createdAt">
      <el-input v-model="dataForm.createdAt" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="updatedAt">
      <el-input v-model="dataForm.updatedAt" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="0(未删除),1已删除" prop="deletedFlag">
      <el-input v-model="dataForm.deletedFlag" placeholder="0(未删除),1已删除"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          uid: '',
          orderNo: '',
          imageUrl: '',
          transferType: '',
          taxPrice: '',
          taxPoint: '',
          accountNo: '',
          bankName: '',
          realName: '',
          phone: '',
          status: '',
          createdAt: '',
          updatedAt: '',
          deletedFlag: ''
        },
        dataRule: {
          uid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          orderNo: [
            { required: true, message: '订单号不能为空', trigger: 'blur' }
          ],
          imageUrl: [
            { required: true, message: '退税凭证不能为空', trigger: 'blur' }
          ],
          transferType: [
            { required: true, message: '退税方式:1(银行卡);2(支付宝);3(微信)...不能为空', trigger: 'blur' }
          ],
          taxPrice: [
            { required: true, message: '退税金额不能为空', trigger: 'blur' }
          ],
          taxPoint: [
            { required: true, message: '税点不能为空', trigger: 'blur' }
          ],
          accountNo: [
            { required: true, message: '银行卡号或支付宝、微信账号不能为空', trigger: 'blur' }
          ],
          bankName: [
            { required: true, message: '开户行不能为空', trigger: 'blur' }
          ],
          realName: [
            { required: true, message: '持卡人姓名不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '电话不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '申请退税状态:0(已提交,未审核);1(已审核);2(已到账，审核结束)不能为空', trigger: 'blur' }
          ],
          createdAt: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          updatedAt: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          deletedFlag: [
            { required: true, message: '0(未删除),1已删除不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/biz/drawbackRecord/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.uid = data.drawbackRecord.uid
                this.dataForm.orderNo = data.drawbackRecord.orderNo
                this.dataForm.imageUrl = data.drawbackRecord.imageUrl
                this.dataForm.transferType = data.drawbackRecord.transferType
                this.dataForm.taxPrice = data.drawbackRecord.taxPrice
                this.dataForm.taxPoint = data.drawbackRecord.taxPoint
                this.dataForm.accountNo = data.drawbackRecord.accountNo
                this.dataForm.bankName = data.drawbackRecord.bankName
                this.dataForm.realName = data.drawbackRecord.realName
                this.dataForm.phone = data.drawbackRecord.phone
                this.dataForm.status = data.drawbackRecord.status
                this.dataForm.createdAt = data.drawbackRecord.createdAt
                this.dataForm.updatedAt = data.drawbackRecord.updatedAt
                this.dataForm.deletedFlag = data.drawbackRecord.deletedFlag
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/biz/drawbackRecord/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'uid': this.dataForm.uid,
                'orderNo': this.dataForm.orderNo,
                'imageUrl': this.dataForm.imageUrl,
                'transferType': this.dataForm.transferType,
                'taxPrice': this.dataForm.taxPrice,
                'taxPoint': this.dataForm.taxPoint,
                'accountNo': this.dataForm.accountNo,
                'bankName': this.dataForm.bankName,
                'realName': this.dataForm.realName,
                'phone': this.dataForm.phone,
                'status': this.dataForm.status,
                'createdAt': this.dataForm.createdAt,
                'updatedAt': this.dataForm.updatedAt,
                'deletedFlag': this.dataForm.deletedFlag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
